package com.atguigu.dga.governance.service.impl;

import com.atguigu.dga.governance.service.GovernanceAssessGlobalService;
import com.atguigu.dga.governance.service.GovernanceAssessTableService;
import com.atguigu.dga.governance.service.GovernanceAssessTecOwnerService;
import com.atguigu.dga.governance.service.MainAssessService;
import com.atguigu.dga.meta.service.TableMetaInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * @Description: TODO
 * @Author: lay
 * @Date: 2024/7/2 16:56
 */
@Service
public class MainAssessServiceImpl implements MainAssessService {
    
    @Autowired
    private TableMetaInfoService tableMetaInfoService;
    @Autowired
    private GovernanceAssessDetailServiceImpl governanceAssessDetailService;
    @Autowired
    private GovernanceAssessTableService governanceAssessTableService;
    @Autowired
    private GovernanceAssessTecOwnerService governanceAssessTecOwnerService;
    @Autowired
    private GovernanceAssessGlobalService governanceAssessGlobalService;
    @Value("${default.database}")
    private String defaultDatabase;

    /**
     * 总体调度
     *      1. 获取元数据
     *      2. 做考评
     *      3. 评分汇总
     * @param schemaName
     * @param assessDate
     */
    @Override
    public void mainAssess(String schemaName, String assessDate) {
        try {
            //1. 获取元数据
            tableMetaInfoService.initTableMetaInfo(schemaName, assessDate);
            //2. 做考评
            governanceAssessDetailService.mainAssess(assessDate);
            //3. 评分汇总
            governanceAssessTableService.calcTableScore(assessDate);
            governanceAssessTecOwnerService.calcTecOwnerScore(assessDate);
            governanceAssessGlobalService.calcGlobalScore(assessDate);
            
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("总体调度失败....");
        }
    }

    @Override
    public void mainAssess(String date) {
        mainAssess(defaultDatabase, date);
    }

    /**
     * 任务调度
     */
    @Scheduled(cron = "00 41 20 * * *")
    public void mainAssess() {
        mainAssess(defaultDatabase, "2023-05-02");
    }
}
